package com.yizhiliulianta.sku.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class SkuController {
    @GetMapping("/test")
    public String test() {
        return "hello sku";
    }

    @GetMapping("/testTimeOut")
    public String testTimeOut() throws InterruptedException {
        Thread.sleep(3000);
        return "hello sku timeOut";
    }

    @GetMapping("/testHystrix")
    public String testHystrix() throws InterruptedException {
        return "hello Hystrix";
    }

    @GetMapping("/testHystrixTimeOut")
    @HystrixCommand(fallbackMethod = "testHystrixTimeOutHandler",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public String testHystrixTimeOut() throws InterruptedException {
        Thread.sleep(5000);
        return "hello Hystrix timeOut";
    }

    public String testHystrixTimeOutHandler(){
        return "接口降级了";
    }
}
